import axios, { AxiosRequestConfig } from 'axios'
import { MyResponseType } from '@/types'
const instance = axios.create({
	baseURL: '/api'
})

const request = async <T = any>(config: AxiosRequestConfig):Promise<MyResponseType<T>> => {
	try {
		const { data } = await instance.request<MyResponseType<T>>(config)
		data.code === 0
		? console.log(data.message) //成功消息提示
		: console.error(data.message) //失败消息提示
		return data
	}catch(error){
		const message = error.message || '请求失败'
		console.log(error.message)
		return{
			code: -1,
			message,
			data: nunll as any
		}
	}
}
export default request